Get Styles from Word Template

Good Morning everyone,

I am working with DOORS 8.2 and I'm trying to get all the styles of a MS Word Template. I have tried using an Word OLE Automation Object but it doesn't work.

Does somebody know how to help?

This is my code:
 

OleAutoObj objStyles
OleAutoObj objStyle 
oleGet(objWordDocument_g, "Styles", objStyles)
int count = -1
oleGet(objStyles, "count", count)
int i
for( i = 1; i <= count; i++ )
{
   put( oleAutoArgs_g, i )
   oleMethod( objStyles, "Item", oleAutoArgs_g, objStyle )
   oleGet( objStyle, "Name", oleGetReturnString_g )
   print oleGetReturnString_g "\n"
}

 


Regards and already many Thanks in advance.

Boitumelo

 


Boitumelo - Thu May 26 02:57:28 EDT 2011

Re: Get Styles from Word Template
Peter_Albert - Thu May 26 04:11:58 EDT 2011

Good morning,

I am not an OLE expert, but with two modifications, I can get the styles:

1) I guess your "objWordDocument_g" is a handle on the Word Application, not a handle on the active Document. I have therefore added a

oleGet(objWord, "ActiveDocument", objDoc)

 


2) I had to create and delete the oleAutoArgs_g within the loop

The overall script looks like this:

 

OleAutoObj  objWord              = null
OleAutoObj  objDoc               = null
OleAutoObj  objStyles            = null
OleAutoObj  objStyle             = null
                                 
OleAutoArgs oleAutoArgs_g        
int         count                = -1
int         i
string      oleGetReturnString_g = ""
 
objWord = oleGetAutoObject("Word.Application") 
if (null objWord){objWord = oleCreateAutoObject("Word.Application")} 
if (!null objWord)
{ // Successfully opened Word
  oleGet(objWord, "ActiveDocument", objDoc)
  if (!null objDoc)
  { // Successfully got handle on Active Document
    oleGet(objDoc, "Styles", objStyles)
    if (!null objStyles)
    { // Successfully got handle on styles
      oleGet(objStyles, "count", count)
      for( i = 1; i <= count; i++ )
      { // Loop through styles
        oleAutoArgs_g = create
        put(oleAutoArgs_g, i)
        oleMethod(objStyles, "Item", oleAutoArgs_g, objStyle)
        if (!null objStyle)
        { // Successfully got handle on one style
          oleGet(objStyle, "NameLocal", oleGetReturnString_g)
          print oleGetReturnString_g "\n"
        } // Successfully got handle on one style
        else {print "No handle on style " i "\n"}
        delete oleAutoArgs_g 
      } // Loop through styles
    } // Successfully got handle on styles
    else {print "No handle on styles\n"}
  } // Successfully got handle on styles
  else {print "No handle on Active Document\n"}
} // Successfully opened Word
else {print "No handle on Word\n"}

 


I have a faint memory that there was an ole include file available somewhere, with which you could write code à la

 

objStyles = objDoc."Sytles"

which is easier to write and read. Probably someone can give a hint here.

Regards,

Peter

Re: Get Styles from Word Template
Boitumelo - Thu May 26 05:02:40 EDT 2011

It worked.

Thanks :)